import type { App } from 'vue'
import * as monaco from 'monaco-editor'
import { install as VueMonacoEditor, loader } from '@guolao/vue-monaco-editor'
import { setupMonacoWorkers } from '../components/editor/monaco-workers.ts'

export default function createMonacoLocalPlugin() {
    return {
        install(app: App) {
            // 设置 worker 映射（必须早于编辑器创建）
            setupMonacoWorkers()
            // 告诉 loader 使用本地安装的 monaco（而非 CDN）
            loader.config({ monaco })
            // 注册组件
            app.use(VueMonacoEditor)
        },
    }
}
